package tp

import (
	"r_log"
	"util"
)

const C_CountOfHoldingPeriod = 1

//检查两点持仓情况：
//（1）本周期是否已持仓该股，持有则返回true，不再推荐该股
//（2）检查总账户中该股持仓周期数是否已到2，到2则返回true
func (sacc *SubAccount) CheckHolding(stkid util.StkID) bool {
	if _, ok := sacc.Holdings[stkid]; ok {
		r_log.RecomLogger.Info("stkid(%v): has been in holdings of this account", stkid)
		return true
	}
	return sacc.ParentAcc.checkHolding(stkid)
}

func (pacc *Account) checkHolding(stkid util.StkID) bool {
	if len(pacc.Holdings) >= util.GetDifferentStockCount(pacc.Version) {
		return false
	}
	count, ok := pacc.Holdings[stkid]
	if !ok {
		return false
	}
	if count >= C_CountOfHoldingPeriod {
		r_log.RecomLogger.Info("stkid(%v): has been in holdings of %v accounts belong to the user", stkid, count)
		return true
	}
	return false
}
